package com.luckyframe.project.jmeter;

import org.apache.jmeter.engine.DistributedRunner;
import org.apache.jmeter.gui.action.ActionNames;
import org.apache.jorphan.collections.HashTree;

import java.util.Arrays;
import java.util.List;

public class JmeterRunner {

    private List<String> remoteAddrs;

    DistributedRunner distributedRunner=new DistributedRunner();






    public void run(HashTree testTree,String action){


        if (action.equals(ActionNames.REMOTE_STOP)) {
            distributedRunner.stop(remoteAddrs);

        } else if (action.equals(ActionNames.REMOTE_SHUT)) {
            distributedRunner.shutdown(remoteAddrs);

        } else if (action.equals(ActionNames.REMOTE_START)) {
            distributedRunner.init(remoteAddrs, testTree);
            distributedRunner.start(remoteAddrs);

        } else if (action.equals(ActionNames.REMOTE_START_ALL)) {
            distributedRunner.init(getRemoteHosts(), testTree);
            distributedRunner.start();

        } else if (action.equals(ActionNames.REMOTE_STOP_ALL)) {
            distributedRunner.stop(getRemoteHosts());

        } else if (action.equals(ActionNames.REMOTE_SHUT_ALL)) {
            distributedRunner.shutdown(getRemoteHosts());

        } else if (action.equals(ActionNames.REMOTE_EXIT)) {
            distributedRunner.exit(remoteAddrs);

        } else if (action.equals(ActionNames.REMOTE_EXIT_ALL)) {
            distributedRunner.exit(remoteAddrs);
        }

    }

    public List<String> getRemoteAddrs() {
        return remoteAddrs;
    }

    public void setRemoteAddrs(List<String> remoteAddrs) {
        this.remoteAddrs = remoteAddrs;
    }

    private List<String> getRemoteHosts(){
        return Arrays.asList("127.0.0.1");
    }
}
